# coding: utf-8
"""

重启资源管理器
"""
from funcs import get_logging, sys_encode, kill, getPid
from win32api import ShellExecute
import platform
import os
import time


logging = get_logging()

def doubleClickExe(exePath):
	"""

	双击应用
	"""
	ShellExecute(0, 'open', exePath, '','',1)

def killExe(exeName):
	"""

	杀死应用
	"""
	while True:
		pid = getPid(exeName)
		if pid:
			text = kill(pid)
			logging.info(sys_encode(text))
		else:
			logging.info(sys_encode('没有应用进程...'))
			break
		time.sleep(1)
		
def startExe(exePath):
	"""

	启动应用
	"""
	doubleClickExe(exePath)

def restartexe(exeName, exePath):
	"""

	重启应用
	"""
	killExe(exeName)
	startExe(exePath)

def restartExplorer():
	"""

	重启资源管理器
	"""
	exeName = u'explorer'
	exePath = os.path.join(os.environ.get('SystemRoot'), 'explorer.exe')
	restartexe(exeName, exePath)

if __name__ == '__main__':
	restartExplorer()